<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-24 14:42
 *
 * Version: 2.0
 */

namespace App\Modules\Message\Controllers;


use App\Lib\Facades\FLAuth;
use App\Modules\Message\Services\MessageService;
use App\Modules\Message\Transformers\getMessageListTransformer;
use Flower\Core\Http\BaseController;
use Flower\Core\Http\Request;

class MessageController extends BaseController
{
	private $messageService;
	public function __construct(MessageService $messageService)
	{
		$this->messageService = $messageService;
	}


	public function getRules()
	{
		return parent::getRules(); // TODO: Change the autogenerated stub
	}

	/**
	 * 测试消息添加接口
	 */
//	public function addMessage(){
//		$params = [
//			'scene' => config('constant.message.scene.wx'),
//			'category' => config('constant.message.category.order'),
//			'title' => '订单预约78_sfdd',
//			'content' => '订单预约78_sf,预约成功!'
//		];
//		$userId = 1;
//		$this->messageService->addMessage($params,$userId);
//	}

	/**
	 * 查询获取通知接口
	 * @param Request $request
	 * @return mixed
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 * @author Happy dong
	 * @modifiedTime 2019-08-09 17:11
	 */
	public function getWxList(Request $request){
		$List = $this->messageService->getList(FLAuth::id(),config('constant.message.scene.wx'),null,$request->page_size,false);
		return $this->display($List);
	}

	/**
	 * App 查询获取通知接口
	 * @param Request $request
	 * @return mixed
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 * @author Happy dong
	 * @modifiedTime 2019-08-09 17:12
	 */
	public function getAppList(Request $request){
		$List = $this->messageService->getList(FLAuth::id(),config('constant.message.scene.app'),$request->type,$request->page_size,true,$request->store_id);
		return $this->display((new getMessageListTransformer($List))->transformer());
	}

	/**
	 * 统计
	 * @param Request $request
	 * @return mixed
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 */
	public function  getAppCount(Request $request){
		$List = $this->messageService->getAppCountData(FLAuth::id(),config('constant.message.scene.app'));
		return $this->display($List);
	}

	/**
	 * 微信信息已读点击接口
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function readWxMessage(Request $request){
		$res = $this->messageService->readMessage($request->message_log_id);
		if(empty($res)) return $this->error("信息已读状态修改失败！");
		return $this->success("信息已读状态修改成功");
	}

	/**
	 * App信息已读点击接口
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 */
	public function readAppMessage(Request $request){
		$res = $this->messageService->readMessage($request->message_id);
		if(empty($res)) return $this->error("信息已读状态修改失败！");
		return $this->success("信息已读状态修改成功");
	}

	/**
	 * 全部消息已读接口微信
	 * @return mixed
	 */
	public function readAllWxMessage(){
		$res = $this->messageService->readAll(FLAuth::id(),config('constant.message.scene.wx'));
		if($res) return $this->success("消息全部已读");
		return $this->success("没有未读消息");
	}

	/**
	 *  全部消息已读接口app
	 * @return mixed
	 */
	public function readAllAppMessage(){
		$res = $this->messageService->readAll(FLAuth::id(),config('constant.message.scene.app'));
		if($res) return $this->success("消息全部已读");
		return $this->success("没有未读消息");
	}


}